import { UserConfig, ConfigEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'
import legacy from '@vitejs/plugin-legacy'
import { vite2Ext } from 'apite'
import viteSvgIcons from 'vite-plugin-svg-icons'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
import { defineConfig } from 'vite';
const pathResolve = (pathStr: string) => {
  return resolve(__dirname, pathStr)
}
export default ({ command, mode }: ConfigEnv): UserConfig => {
  
  return {
    base: './',
    envDir: './viteEnv',
    server: {
      host: '0.0.0.0'
    },
    plugins: [
      vue(),
      viteCommonjs(),
      vueJsx(),
      vite2Ext({
        dir: 'mock'
      }) as any,
      legacy({
        targets: ['defaults', 'not IE 11']
      }),
      viteSvgIcons({
        // 指定需要缓存的图标文件夹
        iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
        // 指定symbolId格式
        symbolId: 'icon-[dir]-[name]'
      })
    ],
    resolve: {
      alias: [
        {
          find: 'vue-i18n',
          replacement: 'vue-i18n/dist/vue-i18n.cjs.js'
        },
        {
          find: '@',
          replacement: pathResolve('src') + '/'
        }
      ]
    },
    css: {
      preprocessorOptions: {
        less: {
          // modifyVars: generateModifyVars(),
          javascriptEnabled: true
        }
      }
    }
  }
}
